package com.zsx.shopping.auth.controller;

import com.zsx.shopping.auth.form.LoginForm;
import com.zsx.shopping.auth.service.LoginService;
import com.zsx.shopping.common.api.R;
import com.zsx.shopping.common.session.UserVO;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;

@RestController
@RequestMapping("/auth")
public class LoginController {

    @Resource
    private LoginService loginService;

    @PostMapping("/login")
    public R<Void> login(@Valid @RequestBody LoginForm loginForm) {
        loginService.login(loginForm);
        return R.success();
    }

    @PutMapping("/logout")
    public R<Void> logout() {
        loginService.logout();
        return R.success();
    }

    @GetMapping("/user")
    public R<UserVO> getUser() {
        return R.success(loginService.getUser());
    }
}
